﻿#include <iostream>
#include <stack>
#include <ctime>
#include <exception>
#include <string>
#include <queue>

using namespace std;

void test_stack(long & value)
{
	cout << "\n test_stack()..... \n";

	stack<string>c;
	char buf[10];
	clock_t timeStart = clock();
	for (long i = 0; i < value; i++)
	{
		try
		{
			snprintf(buf, 10, "%d", rand());
			c.push(buf);
		}
		catch (const std::exception& p)
		{
			cout << "i= " << i << " " << p.what() << endl;
			abort();
		}
	}

	cout << "milli-seconds:" << (clock() - timeStart) << endl;
	cout << "stack.size() " << c.size() << endl;
	cout << "stack.top() " << c.top() << endl;

	c.pop();

	cout << "stack.size() " << c.size() << endl;

	cout << "stack.top() " << c.top() << endl;

}

void test_queue(long & value)
{
	cout << "\n test_queue()..... \n";
	queue<string>c;
	char buf[10];
	clock_t timeStart = clock();
	for (long i = 0; i < value; i++)
	{
		try
		{
			snprintf(buf, 10, "%d", rand());
			c.push(string(buf));
		}
		catch (const std::exception& p)
		{
			cout << "i= " << i << " " << p.what() << endl;
			abort();
		}
	}

	cout << c.back()  <<"\t"<< c.front() << endl;
	cout << "c.size()  " << c.size() << "\n";
	c.pop();
	cout << "c.pop()" << c.size() <<"\n";
}

int main(void)
{
	long value = 1000000;
	//test_stack(value);
	test_queue(value);
	return 0;
}
